package com.emser.unc.client.view;

import com.emser.unc.client.CloudMobile;
import com.emser.unc.client.presenter.ReportsPresenter;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class ReportsView extends Composite implements ReportsPresenter.Display {
	private VerticalPanel verticalPanel;
	private Button btnSaleReport;
	private Button btnNoSaleReport;
	private int heightSPanel;
	public ReportsView() {
		verticalPanel = new VerticalPanel();
		initWidget(verticalPanel);
		verticalPanel.setSize("100%", CloudMobile.get().getHeightPanelCenter()+"px");
		heightSPanel = CloudMobile.get().getHeightPanelCenter() - 60;
		initTitleHPanel();
		initCenterPanel();
	}

	private void initCenterPanel() {
		SimplePanel sPanel = new SimplePanel();
		sPanel.setStyleName("gwt-SPReportV");
		sPanel.setSize("100%-1px", heightSPanel+ "px");
		FlexTable flexTable = new FlexTable();
		flexTable.setSize("320px", "80px");
		
		btnSaleReport = new Button(CloudMobile.constants.saleReports());
		flexTable.setWidget(0, 0, btnSaleReport);
		btnSaleReport.setSize("300px", "30px");
		flexTable.getCellFormatter().setWidth(0, 0, "100%");
		flexTable.getCellFormatter().setHeight(0, 0, "30px");
		
		btnNoSaleReport = new Button(CloudMobile.constants.saleNoReports());
		flexTable.setWidget(1, 0, btnNoSaleReport);
		flexTable.getCellFormatter().setHeight(1, 0, "30px");
		flexTable.getCellFormatter().setWidth(1, 0, "100%");
		btnNoSaleReport.setSize("300px", "30px");
		flexTable.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
		flexTable.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER);
		flexTable.getCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_BOTTOM);
		flexTable.getCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_TOP);
		sPanel.add(flexTable);
		verticalPanel.add(sPanel);
	    verticalPanel.setCellHorizontalAlignment(sPanel, HasHorizontalAlignment.ALIGN_CENTER);
	    verticalPanel.setCellWidth(sPanel, "100%");
	    verticalPanel.setCellHeight(sPanel, heightSPanel+"px");
	}


	private void initTitleHPanel() {
		SimplePanel simplePanel = new SimplePanel();
		simplePanel.setStyleName("gwt-SimplePanelM1");
		verticalPanel.add(simplePanel);
		verticalPanel.setCellHorizontalAlignment(simplePanel, HasHorizontalAlignment.ALIGN_CENTER);
		verticalPanel.setCellHeight(simplePanel, "40px");
		verticalPanel.setCellWidth(simplePanel, "100%");
		simplePanel.setSize("100%", "38px");
	}

	@Override
	public HasClickHandlers getSaleReportButton() {
		return btnSaleReport;
	}

	@Override
	public HasClickHandlers getNoSaleReportButton() {
		return btnNoSaleReport;
	}
	@Override
	public Widget asWidget() {
		return this;
	}

}
